package lcci;

import java.util.HashMap;
import java.util.Map;

public class leetcode0102 {
    public static void main(String[] args) {

    }

    public boolean CheckPermutation(String s1, String s2) {
        if (s1 == null || s2 == null || s1.length() != s2.length()) {
            return false;
        }

        Map<Character, Integer> counts1 = new HashMap<>();
        for (char s : s1.toCharArray()) {
            counts1.put(s, counts1.getOrDefault(s, 0) + 1);
        }

        Map<Character, Integer> counts2 = new HashMap<>();
        for (char s : s2.toCharArray()) {
            counts2.put(s, counts2.getOrDefault(s, 0) + 1);
        }

        for (Map.Entry<Character, Integer> entry : counts1.entrySet()) {
            if (!counts2.containsKey(entry.getKey()) || !counts2.get(entry.getKey()).equals(entry.getValue())) {
                return false;
            }
        }

        return true;
    }
}
